import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';

class LoadingUtils {
  static LoadingUtils get share => LoadingUtils._share();

  static LoadingUtils? _instance;

  LoadingUtils._();

  factory LoadingUtils._share() {
    _instance ??= LoadingUtils._();
    return _instance!;
  }

  Timer? _timer;
  Color? toastBgColor;
  Color? toastTextColor;

  // static TransitionBuilder? init(
  //     {TransitionBuilder? builder,
  //     Color? toastBgColor,
  //     Color? toastTextColor}) {
  //   share.toastBgColor = toastBgColor;
  //   share.toastTextColor = toastTextColor;
  //
  //   return (BuildContext context, Widget? child) {
  //     if (builder != null) {
  //       return builder(context, FlutterEasyLoading(child: child));
  //     } else {
  //       return FlutterEasyLoading(child: child);
  //     }
  //   };
  // }

  static show({String? data, bool dismissOnTap = false, int timeOut = 60}) {
    share._timer?.cancel();
    share._timer = Timer(Duration(seconds: timeOut), () {
      dismiss();
      share._timer = null;
    });
    SmartDialog.showLoading(msg: data ?? '',displayTime: Duration(seconds: timeOut));
  }

  static showProgress({required double progress, String? data}) {
    SmartDialog.showLoading(msg: data ?? '',displayTime: Duration(seconds: progress.toInt()));
  }

  static showSuccess({String? data, int? seconds = 2}) {
    SmartDialog.showNotify(msg: data ?? '', notifyType: NotifyType.success);
  }

  static showError({String? data, int? seconds = 2}) {
    SmartDialog.showNotify(msg: data ?? '', notifyType: NotifyType.failure);
  }

  static showInfo({String? data, int? seconds = 2}) {
    SmartDialog.showNotify(msg: data ?? '', notifyType: NotifyType.error,displayTime: Duration(seconds: 2));
  }

  static showToast(
      {String? data}) {
    SmartDialog.showToast(data ?? '');
  }

  static showAlert({required WidgetBuilder builder,Alignment? alignment}) {
    SmartDialog.show(builder: builder,alignment: alignment ?? Alignment.center);
  }

  static dismiss() {
    SmartDialog.dismiss();
  }
}
